package com.yuanchu.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.common.utils.PageUtils;
import com.yuanchu.common.utils.Query;
import com.yuanchu.goods.dao.YoshopGoodsCategoryRelDao;
import com.yuanchu.goods.dto.SpecData;
import com.yuanchu.goods.entity.YoshopGoodsCategoryRelEntity;
import com.yuanchu.goods.service.YoshopGoodsCategoryRelService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service("yoshopGoodsCategoryRelService")
public class YoshopGoodsCategoryRelServiceImpl extends ServiceImpl<YoshopGoodsCategoryRelDao, YoshopGoodsCategoryRelEntity> implements YoshopGoodsCategoryRelService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<YoshopGoodsCategoryRelEntity> page = this.page(
                new Query<YoshopGoodsCategoryRelEntity>().getPage(params),
                new QueryWrapper<YoshopGoodsCategoryRelEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<Integer> getGoodsCategoryIds(Integer goodsId) {
        List<Integer> categoryIds = new ArrayList<>();
        List<YoshopGoodsCategoryRelEntity> categorys = this.list(new QueryWrapper<YoshopGoodsCategoryRelEntity>().eq("goods_id", goodsId));
        if (CollectionUtils.isNotEmpty(categoryIds)){
            return null;
        }
        categorys.forEach(category -> {
            categoryIds.add(category.getCategoryId());
        });
        return categoryIds;
    }



}